package com.aabte.design2.behavioral.memento.v1;

/**
 * 备忘录类保存有编辑器的过往状态
 *
 * @author Daniel
 * @version 1.0
 * @date 2020/5/4
 */
public class Snapshot {

    private Editor editor;

    private String text;
    private int curX;
    private int curY;
    private int selectionWidth;

    public Snapshot(Editor editor, String text, int curX, int curY, int selectionWidth) {
        this.editor = editor;
        this.text = text;
        this.curX = curX;
        this.curY = curY;
        this.selectionWidth = selectionWidth;
    }

    /**
     * 在某一时刻，编辑器之前的状态可以使用备忘录对象来恢复
     */
    public void restore() {
        editor.setText(text);
        editor.setCursor(curX, curY);
        editor.setSelectionWidth(selectionWidth);
    }
}
